import Vue from 'vue'
import Router from 'vue-router'
import Index from '@/view/Index'
import { resolve } from 'url';
import { resolveObject } from 'url';
import { getStore } from '../utils/local';

Vue.use(Router)

const router = new Router({
    base: '/tide/',
    routes: [{
        path: '/',
        name: 'index',
        component: Index
    },
    {
        path: '/home',
        name: 'home',
        component: resolve => require(['@/view/Home.vue'], resolve),
        children: [
            {
                path: '/ads',
                name: '广告位',
                component: resolve => require(['@/view/ads/Ads.vue'], resolve)
            },
            {
                path: '/adsEdit',
                name: '编辑',
                component: resolve => require(['@/view/ads/AdsEdit.vue'], resolve)
            },
            {
                path: '/filmSetting',
                name: '基本设置',
                component: resolve => require(['@/view/film/FilmBaseSetting.vue'], resolve)
            },
            {
                path: '/filmManger',
                name: '电影管理',
                component: resolve => require(['@/view/film/FilmManger.vue'], resolve)
            },
            {
                path: '/filmAdd',
                name: '添加电影',
                component: resolve => require(['@/view/film/FilmAdd.vue'], resolve)
            },
            {
                path: '/categoryManger',
                name: '类目管理',
                component: resolve => require(['@/view/film/CategoryManger.vue'], resolve)
            },
            {
                path: '/filmAds',
                name: '映前广告',
                component: resolve => require(['@/view/film/FilmAds.vue'], resolve)
            },
            {
                path: '/filmAdsAdd',
                name: '添加广告',
                component: resolve => require(['@/view/film/FilmAdsAdd.vue'], resolve)
            },
            {
                path: '/orderSetting',
                name: '基本设置',
                component: resolve => require(['@/view/order/OrderSetting.vue'], resolve)
            },
            {
                path: '/menuManger',
                name: '菜单管理',
                component: resolve => require(['@/view/order/MenuManger.vue'], resolve)
            },
            {
                path: '/classification',
                name: '菜品分类',
                component: resolve => require(['@/view/order/Classification.vue'], resolve)
            },
            {
                path: '/menuAdd',
                name: '添加菜品',
                component: resolve => require(['@/view/order/MenuAdd.vue'], resolve)
            },
            {
                path: '/orderRecord',
                name: '订单记录',
                component: resolve => require(['@/view/order/OrderRecord.vue'], resolve)
            },
            {
                path: '/cityManger',
                name: '城市管理',
                component: resolve => require(['@/view/city/CityManger.vue'], resolve)
            },
            {
                path: '/cityAdd',
                name: '添加城市',
                component: resolve => require(['@/view/city/CityAdd.vue'], resolve)
            },
            {
                path: '/articleManger',
                name: '文章管理',
                component: resolve => require(['@/view/article/ArticleManger.vue'], resolve)
            },
            {
                path: '/articleEdit',
                name: '编辑文章',
                component: resolve => require(['@/view/article/ArticleEdit.vue'], resolve)
            },
            {
                path: '/articleType',
                name: '栏目管理',
                component: resolve => require(['@/view/article/ArticleType.vue'], resolve)
            },
            {
                path: '/thirdManger',
                name: '第三方链接',
                component: resolve => require(['@/view/third/ThirdManger.vue'], resolve)
            },
            {
                path: '/thirdGameAds',
                name: '游戏广告',
                component: resolve => require(['@/view/third/ThirdGameAds.vue'], resolve)
            },
            {
                path: '/editGameAd',
                name: "编辑游戏广告",
                component: resolve => require(['@/view/third/ThirdGameAdsEdit.vue'], resolve)
            },
            {
                path: '/thirdGames',
                name: '第三方游戏',
                component: resolve => require(['@/view/third/ThirdGame.vue'], resolve)
            },
            {
                path: '/editGame',
                name: '编辑游戏',
                component: resolve => require(['@/view/third/ThirdGameEdit.vue'], resolve)

            },
            {
                path: '/thirdBooks',
                name: '第三方书吧',
                component: resolve => require(['@/view/third/ThirdBook.vue'], resolve)
            },
            {
                path: '/thirdBookAds',
                name: '书吧广告',
                component: resolve => require(['@/view/third/ThirdBookAds.vue'], resolve)
            },
            {
                path: '/editBookAd',
                name: '编辑书吧广告',
                component: resolve => require(['@/view/third/ThirdBookAdsEdit.vue'], resolve)
            },
            {
                path: '/editBook',
                name: '编辑书吧',
                component: resolve => require(['@/view/third/ThirdBookEdit.vue'], resolve)
            },
            {
                path: '/bookType',
                name: '书籍类别管理',
                component: resolve => require(['@/view/third/ThirdBookType.vue'], resolve)
            }, {
                path: '/music',
                name: '音乐',
                component: resolve => require(['@/view/third/ThirdMusic.vue'], resolve)
            },
            {
                path: '/editMusic',
                name: '编辑音乐',
                component: resolve => require(['@/view/third/ThirdMusicEdit.vue'], resolve)
            },
            {
                path: '/userManger',
                name: '用户管理',
                component: resolve => require(['@/view/user/User.vue'], resolve)
            },
            {
                path: '/versionManger',
                name: '版本管理',
                component: resolve => require(['@/view/version/Version.vue'], resolve)
            },
            {
                path: '/accountManger',
                name: '账号管理',
                component: resolve => require(['@/view/account/Account.vue'], resolve)
            },
            {
                path: '/roleManger',
                name: '角色管理',
                component: resolve => require(['@/view/account/Role'], resolve)
            }, {
                path: '/unlock',
                name: '解锁统计',
                component: resolve => require(['@/view/statistics/Unlock.vue'], resolve)
            },
            {
                path: '/click',
                name: '模块点击次数',
                component: resolve => require(['@/view/statistics/ModuleClick.vue'], resolve)
            },
            {
                path: '/stay',
                name: '板块停留时长',
                component: resolve => require(['@/view/statistics/ModuleStay.vue'], resolve)
            },
            {
                path: '/openPad',
                name: '开机统计',
                component: resolve => require(['@/view/statistics/OpenPad.vue'], resolve)
            }
        ]
    }
    ]
})
router.beforeEach((to, from, next) => {
    // let menus = router.app.$options.store.getters.getItems
    let menus = JSON.parse(getStore('m'))
    console.log('m', menus)
    if (to.path == '/') {
        next()
    } else {
        if (menus.length > 0) {
            next()
        } else {
            next('/')
        }
    }
})

export default router